﻿/********************************************************************
	created:	2011/05/12
	created:	12:5:2011   20:34
	filename: 	D:\My Documents\Visual Studio 2010\Projects\IntranetMessager\ServiceLibrary\LogWriter.cs
	file path:	D:\My Documents\Visual Studio 2010\Projects\IntranetMessager\ServiceLibrary
	file base:	LogWriter
	file ext:	cs
	author:		
	
	purpose:	输出日志用静态方法汇总。当委托为空时，直接输出到控制台或者DEBUG窗口
*********************************************************************/
using System;

namespace ServiceLibrary
{
    public partial class ServiceRepository
    {
        #region 输出日志的方法

        protected internal static void Printf(string str)
        {
            str = String.Format("{0} - {1}", DateTime.Now, str);
            if (_logHander != null)
            {
                _logHander(str);
            }
            else
            {
                Console.WriteLine(str);
            }
        }

        protected internal static void Printf(string str, Exception ex)
        {
            str = String.Format("{0} - {1}\nReason:{2}", DateTime.Now, str, ex.Message);
            if (_logHander != null)
            {
                _logHander(str);
            }
            else
            {
                Console.WriteLine(str);
            }
        }

        protected internal static void Printf(string str, Exception ex, int uid)
        {
            str = String.Format("{0} - {1} - UID: {2}\nReason:{3}", DateTime.Now, str, uid,
                                ex.Message);
            if (_logHander != null)
            {
                _logHander(str);
            }
            else
            {
                Console.WriteLine(str);
            }
        }

        protected internal static void Printf(string str, int uid)
        {
            str = String.Format("{0} - {1} - UID: {2}", DateTime.Now, str, uid);
            if (_logHander != null)
            {
                _logHander(str);
            }
            else
            {
                Console.WriteLine(str);
            }
        }

        #endregion
    }
}